home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir27 / calctool.zip / XVIEW.C < prev   
C/C++ Source or Header  |  1992-09-09  |  19KB  |  670 lines

  1.  
  2. /*  @(#)xview.c 1.11 89/12/21
  3.  *
  4.  *  These are the XView dependent graphics routines used by calctool.
  5.  *
  6.  *  Copyright (c) Rich Burridge.
  7.  *                Sun Microsystems, Australia - All rights reserved.
  8.  *
  9.  *  Permission is given to distribute these sources, as long as the
  10.  *  copyright messages are not removed, and no monies are exchanged.
  11.  *
  12.  *  No responsibility is taken for any errors or inaccuracies inherent
  13.  *  either to the comments or the code of this program, but if
  14.  *  reported to me then an attempt will be made to fix them.
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include "calctool.h"
  19. #include "color.h"
  20. #include "extern.h"
  21. #include <xview/xview.h>
  22. #include <xview/canvas.h>
  23. #include <xview/cms.h>
  24. #include <xview/font.h>
  25. #include <xview/cursor.h>
  26. #include <xview/sel_svc.h>
  27. #include <xview/sel_attrs.h>
  28. #include <X11/Xlib.h>
  29.  
  30. #define  MENU_SET                       (void) menu_set
  31. #define  NOTIFY_DO_DISPATCH             (void) notify_do_dispatch
  32. #define  NOTIFY_INTERPOSE_DESTROY_FUNC  (void) notify_interpose_destroy_func
  33. #define  SELN_QUERY                     (void) seln_query
  34. #define  XV_SET                         (void) xv_set
  35. #define  WINDOW_DONE                    (void) window_done
  36.  
  37. #define  BIGFONT               "lucidasanstypewriter-18"
  38. #define  DEFFONT               "fixed"
  39. #define  NORMALFONT            "lucidasanstypewriter-12"
  40. #define  SMALLFONT             "lucidasanstypewriter-10"
  41.  
  42. void func_key_proc() ;
  43. int menu_proc() ;
  44.  
  45. Canvas kcanvas, rcanvas ;
  46. Canvas_paint_window cpw, rcpw ;
  47. Event *cur_event ;
  48. Frame frame, rframe ;
  49. Icon calctool_icon ;
  50. Menu menus[MAXMENUS] ;
  51. Notify_value destroy_proc() ;
  52. Seln_client sel_client ;
  53. Seln_holder holder ;
  54. Seln_rank rank = SELN_PRIMARY ;
  55. Seln_result get_proc(), reply_proc() ;
  56. Xv_Cursor help_cursor, main_cursor ;
  57.  
  58. Display *dpy ;
  59. Drawable xid_cpw, xid_rcpw ;
  60. GC gc ;
  61. Window root ;
  62. XColor current_col ;
  63. XFontStruct *bfont, *font, *nfont, *sfont ;
  64. XGCValues gc_val ;
  65.  
  66. unsigned long gc_mask ;
  67. int screen ;
  68. unsigned long backgnd, foregnd ;
  69. unsigned long palette[CALC_COLORSIZE] ;
  70.  
  71. enum menu_type curmenu ;   /* Current menu (if any) being processed. */
  72. int started ;              /* Set just before window is displayed. */
  73.  
  74. short help_cursor_array[16] = {
  75. #include "help.cursor"
  76. } ;
  77.  
  78. unsigned short icon_image[] = {
  79. #include "calctool.icon"
  80. } ;
  81.  
  82. short cicon_image[] = {
  83. #include "calctool.color.icon"
  84. } ;
  85. mpr_static(cicon_pr, 64, 64, 8, cicon_image) ;
  86.  
  87.  
  88. /*ARGSUSED*/
  89. void
  90. canvas_event_proc(canvas, event, arg)
  91. Canvas canvas ;
  92. Event *event ;
  93. caddr_t arg ;
  94. {
  95.   if (!started) return ;
  96.   cur_event = event ;
  97.   process_event(get_next_event(event)) ;
  98. }
  99.  
  100.  
  101. clear_canvas(ctype, color)
  102. enum can_type ctype ;
  103. int color ;
  104. {
  105.   int x, y ;
  106.   unsigned int width, height, bwidth, depth ;
  107.   Window root, window ;
  108.  
  109.        if (ctype == KEYCANVAS) window = xid_cpw ;
  110.   else if (ctype == REGCANVAS) window = xid_rcpw ;
  111.   XGetGeometry(dpy, window, &root, &x, &y, &width, &height, &bwidth, &depth) ;
  112.   if (iscolor) gc_val.foreground = palette[color] ;
  113.   else
  114.     { 
  115.       if (color == WHITE) gc_val.foreground = backgnd ;
  116.       else gc_val.foreground = foregnd ;
  117.     }
  118.   gc_val.function = GXcopy ;
  119.   XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
  120.   XFillRectangle(dpy, window, gc, x, y, width, height) ;
  121. }
  122.  
  123.  
  124. close_frame()
  125. {
  126.   if ((int) xv_get(rframe, XV_SHOW) == TRUE)
  127.     XV_SET(rframe, XV_SHOW, FALSE, 0) ;
  128.   XV_SET(frame, FRAME_CLOSED, TRUE, 0) ;
  129.   rstate = 0 ;
  130. }
  131.  
  132.  
  133. color_area(x, y, width, height, color)
  134. int x, y, width, height, color ;
  135. {
  136.   if (iscolor) gc_val.foreground = palette[color] ;
  137.   else
  138.     { 
  139.       if (color == WHITE) gc_val.foreground = backgnd ;
  140.       else gc_val.foreground = foregnd ;
  141.     }
  142.   gc_val.function = GXcopy ;
  143.   XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
  144.   XFillRectangle(dpy, xid_cpw, gc, x, y,
  145.                  (unsigned int) width, (unsigned int) height) ;
  146. }
  147.  
  148.  
  149. create_menu(mtype)    /* Create popup menu for right button press. */
  150. enum menu_type mtype ;
  151. {
  152.   int i ;
  153.  
  154.   menus[(int) mtype] = xv_create(XV_NULL, MENU_COMMAND_MENU,
  155.                                  MENU_NOTIFY_PROC, menu_proc,
  156.                                  0) ;
  157.   for (i = 0; i < MAXREGS; i++)
  158.     {
  159.       switch (mtype)
  160.         {
  161.           case M_ACC    :                              /* Accuracies. */
  162.           case M_EXCH   :                              /* Register exchange. */
  163.           case M_LSHIFT :                              /* Left shift. */
  164.           case M_RCL    :                              /* Register recall. */
  165.           case M_RSHIFT :                              /* Right shift. */
  166.           case M_STO    : MENU_SET(menus[(int) mtype], /* Register store. */
  167.                                    MENU_STRING_ITEM, num_names[i], i+1,
  168.                                    0) ;
  169.                           break ;
  170.           case M_CON    : if (strlen(con_names[i]))    /* Constants. */
  171.                             MENU_SET(menus[(int) mtype],
  172.                                      MENU_STRING_ITEM, con_names[i], i+1,
  173.                                      0) ;
  174.                           break ;
  175.           case M_FUN    : if (strlen(fun_names[i]))    /* Functions. */
  176.                             MENU_SET(menus[(int) mtype],
  177.                                      MENU_STRING_ITEM, fun_names[i], i+1,
  178.                                      0) ;
  179.         }
  180.     }
  181. }
  182.  
  183.  
  184. destroy_frame()
  185. {
  186.   WINDOW_DONE(frame) ;
  187.   exit(0) ;
  188. }
  189.  
  190.  
  191. destroy_rframe(frame)
  192. Frame frame ;
  193. {
  194.   rstate = 0 ;
  195.   XV_SET(frame, XV_SHOW, FALSE, 0) ;
  196. }
  197.  
  198.  
  199. /*ARGSUSED*/
  200. Notify_value
  201. destroy_proc(client, status)
  202. Notify_client client ;
  203. Destroy_status status ;
  204. {
  205.   exit(0) ;
  206. }
  207.  
  208.  
  209. /*  This routine works rather strangely. Because menu_show does not block
  210.  *  under XView, do_menu cannot return a valid selection. So the menu
  211.  *  selection handling has been moved to the notification procedure, and
  212.  *  the appropriate code in graphics.c has been isolated into a separate
  213.  *  routine. All in all, a bit of a kludge.
  214.  */
  215.  
  216. do_menu(mtype)      /* Popup appropriate menu. */
  217. enum menu_type mtype ;
  218. {
  219.   curmenu =  mtype ;
  220.   menu_show(menus[(int) mtype], kcanvas, cur_event, 0) ;
  221.   return(0) ;
  222. }
  223.  
  224.  
  225. drawline(x1, y1, x2, y2)
  226. int x1, y1, x2, y2 ;
  227. {
  228.   if (iscolor) gc_val.foreground = palette[BLACK] ;
  229.   else gc_val.foreground = foregnd ;
  230.   gc_val.function = GXcopy ;
  231.   XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
  232.   XDrawLine(dpy, xid_cpw, gc, x1, y1, x2, y2) ;
  233. }
  234.  
  235.  
  236. draw_regs()
  237. {
  238.   Rect frect, rrect ;
  239.  
  240.   make_registers() ;
  241.  
  242. /* Force the register popup to appear to the right of the main calctool
  243.  *  frame if it's not already being displayed.
  244.  */
  245.   if (xv_get(rframe, XV_SHOW)) return ;
  246.   frame_get_rect(frame,  &frect) ;
  247.   frame_get_rect(rframe, &rrect) ;
  248.   rrect.r_left = frect.r_left + frect.r_width + 5 ;
  249.   rrect.r_top  = frect.r_top + 21 ;
  250.   frame_set_rect(rframe, &rrect) ;
  251.   XV_SET(rframe, XV_SHOW, TRUE, 0) ;
  252. }
  253.  
  254.  
  255. drawtext(x, y, ctype, fontno, color, str)
  256. enum font_type fontno ;
  257. enum can_type ctype ;
  258. int x, y, color ;
  259. char *str ;
  260. {
  261.   Drawable window ;
  262.  
  263.        if (fontno == SFONT) font = sfont ;
  264.   else if (fontno == NFONT) font = nfont ;
  265.   else if (fontno == BFONT) font = bfont ;
  266.        if (ctype == KEYCANVAS) window = xid_cpw ;
  267.   else if (ctype == REGCANVAS) window = xid_rcpw ;
  268.  
  269.   if (ctype == KEYCANVAS && y == items[(int) DISPLAYITEM].y) x += 70 ;
  270.   if (iscolor) gc_val.foreground = palette[color] ;
  271.   else
  272.     {
  273.       if (color == WHITE) gc_val.foreground = backgnd ;
  274.       else gc_val.foreground = foregnd ;
  275.     }
  276.   gc_val.font = font->fid ;
  277.   gc_val.function = GXcopy ;
  278.   XChangeGC(dpy, gc, GCFont | GCForeground | GCFunction, &gc_val) ;
  279.   XDrawString(dpy, window, gc, x, y, str, strlen(str)) ;
  280. }
  281.  
  282.  
  283. /*ARGSUSED*/
  284. void
  285. func_key_proc(client_data, args)
  286. char *client_data ;
  287. Seln_function_buffer *args ;
  288. {
  289.   get_display() ;
  290. }
  291.  
  292.  
  293. get_display()     /* The GET function key has been pressed. */
  294. {
  295.   if (seln_acquire(sel_client, SELN_SHELF) == SELN_SHELF)
  296.     {
  297.       if (shelf != NULL) free(shelf) ;
  298.       shelf = malloc((unsigned) strlen(display)) ;
  299.       STRCPY(shelf, display) ;         /* Safely keep copy of display. */
  300.     }
  301. }
  302.  
  303.  
  304. XFontStruct *
  305. get_font(name)
  306. char *name ;
  307. {
  308.   XFontStruct *font ;
  309.  
  310.   if (!(font = XLoadQueryFont(dpy, name)))
  311.     if (!(font = XLoadQueryFont(dpy, DEFFONT)))
  312.       {
  313.         perror("couldn't get the default font.") ;
  314.         exit(1) ;
  315.       }
  316.   return(font) ;
  317. }
  318.  
  319.  
  320. get_next_event(event)
  321. Event *event ;
  322. {
  323.   static char eb[4] ;      /* Event buffer. */
  324.   int i ;
  325.  
  326. #ifdef   SUN4_KEYBOARD
  327.   char *rpad = "\000\000\000=/*789456123" ;
  328. #else
  329.   char *rpad = "*-+7894561230.=" ;
  330. #endif /*SUN4_KEYBOARD*/
  331.  
  332.   nextc = event_id(event) ;
  333.   curx = event_x(event) ;
  334.   cury = event_y(event) ;
  335.  
  336.   if (event_is_button(event))
  337.          if (event_is_down(event) && nextc == MS_LEFT) return(LEFT_DOWN) ;
  338.     else if (event_is_down(event) && nextc == MS_MIDDLE) return(MIDDLE_DOWN) ;
  339.     else if (event_is_down(event) && nextc == MS_RIGHT) return(RIGHT_DOWN) ;
  340.     else if (event_is_up(event) && nextc == MS_LEFT) return(LEFT_UP) ;
  341.     else if (event_is_up(event) && nextc == MS_MIDDLE) return(MIDDLE_UP) ;
  342.     else if (event_is_up(event) && nextc == MS_RIGHT) return(RIGHT_UP) ;
  343.  
  344.   if (event_is_ascii(event) && event_is_down(event))
  345.     {
  346.  
  347. /*  With the Sun4 keyboard, the right function keypad generates key_right
  348.  *  events except for the function keys which are not in the range R1-R15.
  349.  *  These return ASCII values which are:
  350.  *     INS (0) = 0,  DEL (.) = 127, Enter = 13, - = 45, + = 43.
  351.  *
  352.  *  These are correct except for INS and DEL. INS can be remapped to ASCII
  353.  *  48 (the digit zero), but there is no easy way to handle DEL remapping,
  354.  *  If you remap DEL to ASCII 46 (decimal point), this also remaps the
  355.  *  Delete key value. For now, this value is left alone.
  356.  */
  357.  
  358. #ifdef   SUN4_KEYBOARD
  359.       if (nextc == 0) nextc = 48 ;            /* Remap INS (0) key. */
  360.       if (nextc == 127) nextc = 46 ;          /* Remap DEL (.) key. */
  361. #endif /*SUN4_KEYBOARD*/
  362.  
  363. /*  All the rest of the ASCII characters. */
  364.                               
  365.       cur_ch = nextc ;    
  366.       return(KEYBOARD) ;
  367.     }                         
  368.                             
  369.   if (event_is_key_right(event) && event_is_up(event))
  370.     {
  371.       for (i = 1; i < 16; i++)
  372.         if (nextc == KEY_RIGHT(i))
  373.           {                 
  374.             cur_ch = rpad[i-1] ;
  375.             return(KEYBOARD) ;
  376.           }                   
  377.     }
  378.  
  379.   if (nextc == KBD_DONE && down) return(EXIT_WINDOW) ;
  380.   if (nextc == LOC_WINEXIT) return(EXIT_WINDOW) ;
  381.   if (nextc == LOC_WINENTER) return(ENTER_WINDOW) ;
  382.  
  383.   if (nextc == WIN_RESIZE) return(CFRAME_REPAINT) ;
  384.   if (nextc == WIN_REPAINT) return(CFRAME_REPAINT) ;
  385.  
  386.   if ((nextc == KEY_LEFT(6)) & event_is_up(event)) return(PUT_ON_SHELF) ;
  387.   if ((nextc == KEY_LEFT(8)) && event_is_up(event)) return(TAKE_FROM_SHELF) ;
  388.   return(LASTEVENTPLUSONE) ;
  389. }
  390.  
  391.  
  392. Seln_result
  393. get_proc(buffer)
  394. Seln_request *buffer ;
  395. {
  396.   issel = 0 ;
  397.   if (*buffer->requester.context == 0)
  398.     {
  399.       if (buffer == (Seln_request *) NULL ||
  400.           *((Seln_attribute *) buffer->data) != SELN_REQ_CONTENTS_ASCII)
  401.         return ;
  402.       selection = buffer->data + sizeof(Seln_attribute) ;
  403.       *buffer->requester.context = 1 ;
  404.     }
  405.   else selection = buffer->data ;
  406.   issel = 1 ;
  407. }
  408.  
  409.  
  410. handle_selection()  /* Handle the GET function key being pressed. */
  411. {
  412.   char context = 0 ;
  413.  
  414.   holder = seln_inquire(rank) ;
  415.   if (holder.state == SELN_NONE) return ;
  416.   SELN_QUERY(&holder, get_proc, &context, SELN_REQ_CONTENTS_ASCII, 0, 0) ;
  417. }
  418.  
  419.  
  420. init_fonts()      /* Null routine; fonts loaded in make_subframes. */
  421. {
  422. }
  423.  
  424.  
  425. init_ws_type()
  426. {
  427.   gtype = XVIEW ;
  428.   started = 0 ;               /* Kludge to correctly handle repaints. */
  429.   return 0 ;
  430. }
  431.  
  432.  
  433. load_colors()      /* Create and load calctool color map. */
  434. {
  435.   u_char red[CALC_COLORSIZE], green[CALC_COLORSIZE], blue[CALC_COLORSIZE] ;
  436.   int i, numcolors ;
  437.  
  438.   iscolor = 0 ;
  439.   if (DisplayCells(dpy, screen) > 2)
  440.     {
  441.       calc_colorsetup(red, green, blue) ;
  442.       iscolor = 1 ;
  443.       numcolors = 0 ;
  444.       for (i = 0; i < CALC_COLORSIZE; i++)
  445.         {
  446.           current_col.flags = DoRed | DoGreen | DoBlue ;
  447.           current_col.red   = (unsigned short) (red[i]   << 8) ;
  448.           current_col.green = (unsigned short) (green[i] << 8) ;
  449.           current_col.blue  = (unsigned short) (blue[i]  << 8) ;
  450.           if (XAllocColor(dpy, DefaultColormap(dpy, screen), ¤t_col) == True)
  451.             palette[numcolors++] = current_col.pixel ;
  452.         }
  453.       if (numcolors < 2)
  454.         {
  455.           FPRINTF(stderr, "%s: cannot allocate colors.\n", progname) ;
  456.           exit(1) ;
  457.         }
  458.     }
  459. }
  460.  
  461.  
  462. make_frames(argc, argv)
  463. int argc ;
  464. char *argv[] ;
  465. {
  466.   xv_init(XV_INIT_ARGS, argc, argv, 0) ;
  467.   frame = xv_create(0, FRAME,
  468.                     FRAME_ICON,        calctool_icon,
  469.                     FRAME_SHOW_LABEL,  FALSE,
  470.                     FRAME_NO_CONFIRM,  TRUE,
  471.                     XV_WIDTH,          TWIDTH,
  472.                     XV_HEIGHT,         THEIGHT + DISPLAY,
  473.                     0) ;
  474.   iscolor = ((int) xv_get(frame, WIN_DEPTH) > 1) ? 1 : 0 ;
  475.   sel_client = seln_create(func_key_proc, reply_proc, (char *) 0) ;
  476.   NOTIFY_INTERPOSE_DESTROY_FUNC(frame, destroy_proc) ;
  477.   rframe = xv_create(frame, FRAME,
  478.                      FRAME_SHOW_LABEL, FALSE,
  479.                      FRAME_NO_CONFIRM, TRUE,
  480.                      FRAME_DONE_PROC,  destroy_rframe,
  481.                      XV_X,             TWIDTH + 15,
  482.                      XV_Y,             0,
  483.                      XV_SHOW,          FALSE,
  484.                      XV_WIDTH,         TWIDTH,
  485.                      XV_HEIGHT,        200,
  486.                      XV_FONT,          nfont,
  487.                      0) ;
  488.  
  489. }
  490.  
  491.  
  492. make_icon()
  493. {
  494.   Server_image sv_image ;
  495.  
  496.   sv_image = xv_create(XV_NULL,            SERVER_IMAGE,
  497.                        SERVER_IMAGE_BITS,  icon_image,
  498.                        SERVER_IMAGE_DEPTH, 1,
  499.                        XV_WIDTH,           64,
  500.                        XV_HEIGHT,          64,
  501.                        0) ;
  502.   calctool_icon = xv_create(XV_NULL,    ICON,
  503.                             XV_WIDTH,   ICONWIDTH,
  504.                             ICON_IMAGE, sv_image,
  505.                             0) ;
  506. }
  507.  
  508.  
  509. make_items()
  510. {
  511.   Server_image help_pr ;
  512.  
  513.   main_cursor = xv_get(kcanvas, WIN_CURSOR) ;
  514.  
  515.   if (iscolor)
  516.     {
  517.       calctool_icon = (Icon) xv_get(frame, FRAME_ICON) ;
  518.       XV_SET(calctool_icon,
  519.              ICON_IMAGE, &cicon_pr,
  520.              0) ;
  521.       XV_SET(frame, FRAME_ICON, calctool_icon, 0) ;
  522.     }
  523.  
  524.   help_pr = xv_create(XV_NULL,           SERVER_IMAGE,
  525.                       XV_WIDTH,          16,
  526.                       XV_HEIGHT,         16,
  527.                       SERVER_IMAGE_BITS, help_cursor_array,
  528.                       0) ;
  529.   help_cursor = xv_create(NULL, CURSOR,
  530.                           CURSOR_XHOT,  0,
  531.                           CURSOR_YHOT,  0,
  532.                           CURSOR_OP,    PIX_SRC | PIX_DST,
  533.                           CURSOR_IMAGE, help_pr,
  534.                           0) ;
  535. }
  536.  
  537.  
  538. make_subframes()
  539. {
  540.   rcanvas = xv_create(rframe, CANVAS, 0) ;
  541.   kcanvas = xv_create(frame, CANVAS,
  542.                       CANVAS_RETAINED,     FALSE,
  543.                       OPENWIN_AUTO_CLEAR,  FALSE,
  544.                       XV_WIDTH,            TWIDTH,
  545.                       XV_HEIGHT,           THEIGHT + DISPLAY,
  546.                       XV_FONT,             nfont,
  547.                       CANVAS_PAINTWINDOW_ATTRS,
  548.                           WIN_CONSUME_EVENTS,
  549.                             MS_LEFT, MS_MIDDLE, MS_RIGHT,
  550.                             WIN_ASCII_EVENTS, KBD_USE, KBD_DONE,
  551.                             LOC_WINENTER, LOC_WINEXIT,
  552.                             WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
  553.                             0,
  554.                           WIN_IGNORE_EVENTS,
  555.                             LOC_MOVE, LOC_DRAG,
  556.                             0,
  557.                           WIN_EVENT_PROC, canvas_event_proc,
  558.                           0,
  559.                       0) ;
  560.  
  561.   rcpw = canvas_paint_window(rcanvas) ;
  562.   cpw = canvas_paint_window(kcanvas) ;
  563.   dpy = (Display *) xv_get(frame, XV_DISPLAY) ;
  564.   xid_cpw  = (Drawable) xv_get(cpw, XV_XID) ;
  565.   xid_rcpw = (Drawable) xv_get(rcpw, XV_XID) ;
  566.  
  567.   screen = DefaultScreen(dpy) ;
  568.   root = RootWindow(dpy, screen) ;
  569.   foregnd = BlackPixel(dpy, screen) ;
  570.   backgnd = WhitePixel(dpy, screen) ;
  571.  
  572.   gc_mask = GCForeground | GCBackground | GCGraphicsExposures ;
  573.   gc_val.foreground = foregnd ;
  574.   gc_val.background = backgnd ;
  575.   gc_val.graphics_exposures = False ;
  576.   gc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
  577.  
  578.   load_colors() ;                 /* Load the calctool colormap. */
  579.  
  580.   bfont = get_font(BIGFONT) ;
  581.   nfont = get_font(NORMALFONT) ;
  582.   nfont_width = nfont->max_bounds.rbearing - nfont->min_bounds.lbearing ;
  583.   sfont = get_font(SMALLFONT) ;
  584. }
  585.  
  586.  
  587. /*ARGSUSED*/
  588. menu_proc(menu, menu_item)
  589. Menu menu ;
  590. Menu_item menu_item ;
  591. {
  592.   int choice ;
  593.  
  594.   choice = (int) menu_get(menu_item, MENU_VALUE) ;
  595.   if (choice) handle_menu_selection(curmenu, choice) ;
  596. }
  597.  
  598.  
  599. /*ARGSUSED*/
  600. Seln_result
  601. reply_proc(item, context, length)
  602. Seln_attribute item ;
  603. Seln_replier_data *context ;
  604. int length ;
  605. {
  606.   int size ;
  607.   char *destp ;
  608.  
  609.   switch (item)
  610.     {
  611.       case SELN_REQ_CONTENTS_ASCII :
  612.  
  613.              if (context->context == NULL)
  614.                {
  615.                  if (shelf == NULL) return(SELN_DIDNT_HAVE) ;
  616.                  context->context = shelf ;
  617.                }
  618.              size = strlen(context->context) ;
  619.              destp = (char *) context->response_pointer ;
  620.              STRCPY(destp, context->context) ;
  621.              destp += size ;
  622.              while ((int) destp % 4 != 0) *destp++ = '\0' ;
  623.              context->response_pointer = (char **) destp ;
  624.              *context->response_pointer++ = 0 ;
  625.              return(SELN_SUCCESS) ;
  626.  
  627.       case SELN_REQ_YIELD :
  628.  
  629.              *context->response_pointer++ = (char *) SELN_SUCCESS ;
  630.              return(SELN_SUCCESS) ;
  631.  
  632.       case SELN_REQ_BYTESIZE :
  633.  
  634.              if (shelf == NULL) return(SELN_DIDNT_HAVE) ;
  635.              *context->response_pointer++ = (char *) strlen(shelf) ;
  636.              return(SELN_SUCCESS) ;
  637.  
  638.       case SELN_REQ_END_REQUEST : return(SELN_SUCCESS) ;
  639.  
  640.       default                   : return(SELN_UNRECOGNIZED) ;
  641.     }
  642. }
  643.  
  644.  
  645. set_cursor(type)
  646. int type ;
  647. {
  648.   switch (type)
  649.     {
  650.       case HELPCURSOR : XV_SET(cpw, WIN_CURSOR, help_cursor, 0) ;
  651.                         break ;
  652.       case MAINCURSOR : XV_SET(cpw, WIN_CURSOR, main_cursor, 0) ;
  653.     }
  654. }
  655.  
  656.  
  657. start_tool()
  658. {
  659.   started = 1 ;
  660.   xv_main_loop(frame) ;
  661. }
  662.  
  663.  
  664. toggle_reg_canvas()
  665. {
  666.   rstate = !rstate ;
  667.   if (rstate) draw_regs() ;
  668.   else XV_SET(rframe, XV_SHOW, FALSE, 0) ;
  669. }
  670.